From 9c0d3f29808944dbab00cc22943f8f0a5eed2f61 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 14 Mar 2018 22:21:02 +0300 Subject: [PATCH] Copy `.pdb` files to `target` directory `.pdb` files are for windows debug info (unlike on linux, debug info is in a separate file). Windows executable actually hard-code paths to `.pdb` files, so debugging mvsc rust programs works even without this patch. However, if you want to distribute the executable to other machines, you'd better distribute both `foo.exe` and `foo.pdb`, because absolute paths won't work on another machine. Having same-named .pdb file alongside the binary would work though. closes #4960 --- src/cargo/ops/cargo_rustc/context.rs | 14 +++++++++----- tests/testsuite/build.rs | 27 +++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/src/cargo/ops/cargo_rustc/context.rs b/src/cargo/ops/cargo_rustc/context.rs index 9f7766e0e..f243aa57a 100644 --- a/src/cargo/ops/cargo_rustc/context.rs +++ b/src/cargo/ops/cargo_rustc/context.rs @@ -1326,13 +1326,17 @@ fn add_target_specific_suffixes( ret.push((".wasm".to_string(), TargetFileType::Normal, true)); } - // rust-lang/cargo#4490 - // - only uplift *.dSYM for binaries. + // rust-lang/cargo#4490, rust-lang/cargo#4960 + // - only uplift debuginfo for binaries. // tests are run directly from target/debug/deps/ - // and examples are inside target/debug/examples/ which already have *.dSYM next to them + // and examples are inside target/debug/examples/ which already have symbols next to them // so no need to do anything. - if target_triple.contains("-apple-") && *target_kind == TargetKind::Bin { - ret.push((".dSYM".to_string(), TargetFileType::DebugInfo, false)); + if *target_kind == TargetKind::Bin { + if target_triple.contains("-apple-") { + ret.push((".dSYM".to_string(), TargetFileType::DebugInfo, false)); + } else if target_triple.ends_with("-msvc") { + ret.push((".pdb".to_string(), TargetFileType::DebugInfo, false)); + } } ret diff --git a/tests/testsuite/build.rs b/tests/testsuite/build.rs index 7a80acb2c..e21597f84 100644 --- a/tests/testsuite/build.rs +++ b/tests/testsuite/build.rs @@ -4179,6 +4179,33 @@ fn uplift_dsym_of_bin_on_mac() { assert_that(&p.bin("d.dSYM"), is_not(existing_dir())); } +#[test] +fn uplift_pdb_of_bin_on_windows() { + if !cfg!(all(target_os = "windows", target_env = "msvc")) { + return + } + let p = project("foo") + .file("Cargo.toml", r#" + [project] + name = "foo" + version = "0.1.0" + "#) + .file("src/main.rs", "fn main() { panic!(); }") + .file("src/bin/b.rs", "fn main() { panic!(); }") + .file("examples/c.rs", "fn main() { panic!(); }") + .file("tests/d.rs", "fn main() { panic!(); }") + .build(); + + assert_that( + p.cargo("build").arg("--bins").arg("--examples").arg("--tests"), + execs().with_status(0) + ); + assert_that(&p.target_debug_dir().join("foo.pdb"), existing_file()); + assert_that(&p.target_debug_dir().join("b.pdb"), existing_file()); + assert_that(&p.target_debug_dir().join("c.pdb"), is_not(existing_file())); + assert_that(&p.target_debug_dir().join("d.pdb"), is_not(existing_file())); +} + // Make sure that `cargo build` chooses the correct profile for building // targets based on filters (assuming --profile is not specified). #[test] -- 2.30.2